package com.ls.lsqc.common.persistence;

import java.util.Date;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ls.lsqc.common.utils.excel.annotation.ExcelField;
import com.ls.lsqc.modules.sys.entity.User;
import com.ls.lsqc.modules.sys.utils.UserUtils;

/**
 * 数据Entity类
 * 
 * @author LiuPeng
 * @version 2016-10-09
 */
public abstract class DataEntity<T> extends BaseEntity<T> {

	private static final long serialVersionUID = 1L;

	// 可用
	protected String enableFlag;
	// 语言
	protected String language;
	// 备注
	protected String remarks;
	// 删除标记
	protected String deleteFlag;
	// 版本号
	protected long version;
	// 创建日期
	protected Date createDate;
	// 更新日期
	protected Date updateDate;
	// 创建者User
	protected User createBy;
	// 更新者User
	protected User updateBy;

	public DataEntity() {
		super();
		this.deleteFlag = DEL_FLAG_NORMAL;
	}

	public DataEntity(Long id) {
		super(id);
	}

	@ExcelField(title = "备注", align = 1, sort = 300)
	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getDeleteFlag() {
		return deleteFlag;
	}

	public void setDeleteFlag(String deleteFlag) {
		this.deleteFlag = deleteFlag;
	}

	public long getVersion() {
		return version;
	}

	public void setVersion(long version) {
		this.version = version;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	/**
	 * 插入之前执行方法，需要手动调用
	 */
	@Override
	public void preInsert() {
		// 不限制ID为UUID，调用setIsNewRecord()使用自定义ID
		/*
		 * if (!this.isNewRecord){ setId(IdGen.uuid()); }
		 */
		User user = UserUtils.getUser();
		if (user.getId() != null) {
			this.updateBy = user;
			this.createBy = user;
		}
		this.updateDate = new Date();
		this.createDate = this.updateDate;
	}

	/**
	 * 更新之前执行方法，需要手动调用
	 */
	@Override
	public void preUpdate() {
		User user = UserUtils.getUser();
		if (user.getId() != null) {
			this.updateBy = user;
		}
		this.updateDate = new Date();
	}

	@JsonIgnore
	public User getCreateBy() {
		return createBy;
	}

	public void setCreateBy(User createBy) {
		this.createBy = createBy;
	}

	@JsonIgnore
	public User getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(User updateBy) {
		this.updateBy = updateBy;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public String getEnableFlag() {
		return enableFlag;
	}

	public void setEnableFlag(String enableFlag) {
		this.enableFlag = enableFlag;
	}

}
